//
//  XTVMsCell2.swift
//  XTMuteOpen
//
//  Created by bushAK on 2024/1/23.
//

import UIKit

class XTVMsCell2: UICollectionViewCell {

    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var logoImgV: UIImageView!
    @IBOutlet weak var backgroundImgV: UIImageView!
    var model : XTVmModel?{
        didSet{
            guard let model = model else {
                return
            }
            nameLabel.text = model.name 
            backgroundImgV.image = getImgWithId(id: model.id)
            
        }
    }
    
    func getImgWithId(id : Int) -> UIImage? {
        // 读取本地缓存
       let document = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last ?? ""
       let path = document + "/\(id).png"
       let data = Data.ReferenceType(contentsOfFile: path)
       if let data = data  {
           let image = UIImage(data: data as Data)
           if image != nil {
               return   image
           }else{
               return UIImage(named: "default_vm_img")
           }
       }else{
           return UIImage(named:  "default_vm_img")
       }
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        logoImgV.image = UIImage(named: "default_logo_pink")!.withColor(UIColor.white )

    }

}
